package xiangmu.schoolpaper.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import xiangmu.schoolpaper.context.BaseContext;
import xiangmu.schoolpaper.result.Result;
import xiangmu.schoolpaper.service.UploadFilesService;

@RestController
@RequestMapping("/uploadfiles")
@Slf4j
@Tag(name = "文件上传接口")
public class UploadFilesController {

    @Autowired
    private UploadFilesService uploadFilesService;

    @Operation(summary = "上传论文")
    @PostMapping("/uploadpapers")
    public Result uploadPapers(@RequestParam("file") MultipartFile file) {
        log.info("接收到论文文件上传请求: {}", file.getOriginalFilename());
        try {
            String upload_id = BaseContext.get("userId").toString();
            String response = uploadFilesService.uploadPapersToFlask(file, upload_id );
            return Result.success(response);
        } catch (Exception e) {
            log.error("上传失败: {}", e.getMessage(), e);
            return Result.error("文件上传失败");
        }
    }
}
